package com.letchat.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letchat.pojo.CommentChild;
import com.letchat.pojo.CommentParent;
import com.letchat.pojo.Subject;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<CommentParent> {

    @Select("select * from comment_parent where subject_id = #{id}")
    List<CommentParent> getCommentParentListBySubjectId(Integer id);

    @Select("select * from comment_child where parent_id = #{id}")
    List<CommentChild> getCommentChildListByParentId(Integer id);

    @Insert("insert into comment_parent (user_id, subject_id, text, create_time) " +
            "VALUES (#{userId},#{subjectId},#{text},#{createTime})")
    void addParentComment(CommentParent commentParent);

    @Delete("delete from comment_parent where subject_id = #{id}")
    void deleteCommentParentBySubjectId(Integer id);

    @Delete("delete from comment_child where parent_id = #{id}")
    void deleteCommentChildByParentId(Integer id);

//    @Select("select * from subject where title like concat('%',#{subject},'%')")
//    List<Subject> listBySearch(String subject);
}
